{% extends 'base.html' %}

{% block content %}
	
	{# 使用length过滤器获取movies长度#}
	<p> {{ movies|length }} Titles</p>
	{% if current_user.is_authenticated %}
	<form method="post">
		Name <input type="text" name="title" autocomplete="off" required>
		Year <input type="text" name="year" autocomplete="off" required>
		<input class="btn" type="submit" name="submit" value="Add">
	</form>
	{% endif %}
	<ul class='movie-list'>
		{% for movie in movies %}
		<li> {{ movie.title}} - {{movie.year}}
			<span class='float-right'>
				<a class='imdb' href="https://www.imdb.com/find?q={{ movie.title }}" target="_blank" title="Find movie on IMDB">IMDb</a>
			</span>
			{% if current_user.is_authenticated %}
			<span class="float-right">
				<a class='btn' href="{{ url_for('edit',movie_id=movie.id) }}">Edit</a>

			</span>
			<span class="float-right">
				<form class='inline-form' method="post" action="{{ url_for('delete',movie_id=movie.id) }}">
					<input style="display:inline" class="btn" type="submit" name="delete" value="Delete" onclick="return confirm('Are u sure?')">
				</form>
			</span>
			{% endif %}
		</li>
		{% endfor %}
	</ul>
	<img alt="walking totoro" class="totoro" src="http://watchlist.helloflask.com/static/images/totoro.gif">
{% endblock %}
